package com.crm.jdy.controller.client;

import com.crm.jdy.common.dto.ClientChargeInfoDto;
import com.crm.jdy.common.dto.ClientContractInfoDto;
import com.crm.jdy.common.pojo.ClientChargeInfo;
import com.crm.jdy.common.pojo.ClientContractInfo;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.client.ClientChargeInfoService;
import com.crm.jdy.service.client.ClientContractInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.validation.constraints.NotNull;

/**
*
* <p>说明： 客户-联系人API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年1月25日
*
*/
@Validated
@Api(tags = "clientChargeInfo", description = "客户-联系人")
@RestController
@RequestMapping("/clientChargeInfo")
public class ClientChargeInfoController{

    @Reference(version = "${service.version}", check = false)
    ClientChargeInfoService clientInfoService;

    @RateLimit()
    @ApiOperation("客户联系人信息")
    @PostMapping("/seleteChargeInfo")
    public ResultVo seleteChargeInfo(@RequestBody ClientChargeInfoDto clientinfo){
        PageInfo<ClientChargeInfo> list = clientInfoService.seleteClientChargeInfoPageInfo(clientinfo);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新联系人")
    @PostMapping("/updatChargeInfo")
    public ResultVo updatChargeInfo(@ApiParam(value = "clientinfo", required = true)
                                    @Validated @RequestBody ClientChargeInfo clientinfo){
        boolean index = clientInfoService.updateClientChargeInfo(clientinfo);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加联系人")
    @PostMapping("/addChargeInfo")
    public ResultVo addChargeInfo(@ApiParam(name = "clientinfo", required = false)
                                  @Validated @RequestBody ClientChargeInfo clientinfo){
        boolean list  = clientInfoService.addClientChargeInfo(clientinfo);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("删除联系人")
    @DeleteMapping("deleteChargeInfo/{chargeId}")
    public ResultVo deleteChargeInfo(@NotNull @ApiParam(name = "chargeId", value = "chargeId", required = true) @PathVariable String  chargeId){
        boolean b = clientInfoService.removeClientChargeInfo(chargeId);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }

}